<%@page import="com.sample.jdbc.JdbcUtils"%>
<%--使用include命令引入公共页面 --%>
<%@include file="/comm/common.jsp"%>
<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分配角色</title>
</head>

<body>
	<%--添加角色的处理过程 --%>
	<%
  //1:调用request对象的getParameter()从请求中获取参数(userid)的值,赋值给字符串变量param_userid
     String param_userid=request.getParameter("userid");
  //2:根据用户编号读取用户名字 
       JdbcUtils jdbcUtils=new JdbcUtils();
       Connection conn=jdbcUtils.getConn();
       Statement stmt=conn.createStatement();
       String userSql="select * from t_user where userid='"+param_userid+"'";
       ResultSet user_rs=stmt.executeQuery(userSql); 
       String fullname="";
       if(user_rs!=null&&user_rs.next()){
          fullname=user_rs.getString("fullname");
       }
     //3:读取角色表中所有角色记录，遍历自动生成复选框组
       String roleSql="select * from t_role";
        ResultSet role_rs=stmt.executeQuery(roleSql); 
  
 %><form id="form1" name="form1" method="post" action="<%=path %>/page/user_role_add_Action.jsp" >
 <input type="hidden" name="userid" value="<%=param_userid %>" />
 
	<table width="700" border="1" align="center">
		<tr>
			<td colspan="2" align="center">分配角色</td>
		</tr>
		<tr>
			<td width="90" align="right">用户名：</td>
			<td width="594"><%=fullname %></td>
		</tr>
		<tr>
			<td align="right">角色：</td>
			<td>
	<%
	  int c=0;

      if(role_rs!=null){  
       while(role_rs.next()) {
         String roleid=role_rs.getString("roleid");
         String rolename=role_rs.getString("rolename");
         c++;
     %> 
     <input type="checkbox" name="roles" id="roles"
				value="<%=roleid %>" /> <label for="roles"><%=rolename %></label> 
	<%
     }
     }
     if(c==0){
        out.print("系统未定义角色");
      }
     %>
			<a href="<%=path%>/page/role_add.jsp">添加角色</a></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input type="submit"
				name="add_user_role_btn" id="add_user_role_btn" value="添加" />
                <a href="<%=path%>/page/user_listing.jsp">返回用户列表</a>
                
			</td>
		</tr>
	</table>
	</form>
</body>
</html>